<?php
namespace App\Controller\Admin;

use App\Query\OrderQuery;
use App\Repository\OrderRepository;

class OrderController extends Controller
{
    // 获取模型
    protected function model()
    {
        return OrderQuery::daili($this->auth()->daili_id);
    }
    
    // 列表
    public function index()
    {
        $model = OrderQuery::query(
            $this->model(),
            $this->inputs('user_id', 'shop_id', 'status', 'product_name', 'time')
        );
        
        if($this->input('all'))
        {
            return $model->get();
        }
        
        return $model->paginate(15)->toArray();
    }
    
    // 发货
    public function express($id)
    {
        $model = $this->model()->find($id);
        
        // 成功
        if($model && OrderRepository::make($model)->express($this->input('name'), $this->input('code')))
        {
            $this->message('ok');
        }
        
        $this->error('error');
    }
}